/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SampleHost;
import java.io.InputStream;
import java.io.IOException;

/**
 *
 * @author Owner
 */
public class PortReader {
    private static final int BYTESIZE = 8;
    public InputStream inputStream;

    public PortReader(PortObject portObject) throws IOException {
        inputStream = portObject.getPort().getInputStream();
    }

    public byte readByte() throws IOException {
        byte[] b = new byte[1];
        inputStream.read(b);
        return b[0];
        //return (byte)inputStream.read();
    }

    public short readHalf() throws IOException {
        short low = readByte();
        short high = readByte();
        return (short)(low | (high<<BYTESIZE));
    }

    public int readWord() throws IOException {
        int low = readHalf();
        int high = readHalf();
        return low | high<<2*BYTESIZE;
    }
}

